package com.navinfo.collect.library.data.entity

import com.squareup.moshi.FromJson
import com.squareup.moshi.JsonClass
import com.squareup.moshi.ToJson

@JsonClass(generateAdapter = false)
enum class DataLayerItemType {
    ///输入框
    DataLayerItemTypeInput,  ///输入框集合
    DataLayerItemTypeInputArray,  ///纯展示文本
    DataLayerItemTypeText,  ///单选框
    DataLayerItemTypeSingleSelection,  ///多选框
    DataLayerItemTypeMultipleSelection
}

@JsonClass(generateAdapter = true)
data class CustomLayerItem(
    ///对应的数据库字段名称
    val key: String,
    ///用来显示控件名称
    val title: String = key,
    ///控件类型
    val type: DataLayerItemType,
    ///非必填项
    val nullable: Boolean = true,
    ///是不是主键
    val primaryKey: Boolean = false,
    ///默认值
    var value: Any,
    ///多选或单选的内容，如果 [isSelect] 为 false 可忽略这字段
    var selectOptions: String,
    ///是否是主名称属性,设置为true，地图上会已该字段内容渲染
    val isMainName: Boolean = false,
    ///简介
    val describe: String,
)

class DataLayerItemTypeAdapter {
    @ToJson
    fun toJson(enum: DataLayerItemType): Int {
        return enum.ordinal;
    }

    @FromJson
    fun fromJson(type: Int): DataLayerItemType {
        return DataLayerItemType.values()[type];
    }
}